<?php
class models_baocao extends connect{
	function listkh()
	{
		$sql="SELECT MaKH, TenKH
				FROM khachhang";
		$this->query_db($sql);
		return $this->fetchAll();
	}
	function listhd($day,$mon,$year,$day1,$mon1,$year1)
	{
		$sql="SELECT MaHD, MaKH, DATE_FORMAT(NgayLap,'%d/%m%/%Y') as NgayLap
			FROM hoadon
			WHERE (DATE_FORMAT(NgayLap,'%d') BETWEEN '$day' AND '$day1')
			AND (DATE_FORMAT(NgayLap,'%m%') BETWEEN '$mon' AND '$mon1')
			AND (DATE_FORMAT(NgayLap,'%Y') BETWEEN '$year' AND '$year1')";
		$this->query_db($sql);
		return $this->fetchAll();
	}
	function _listhd($day,$mon,$year,$day1,$year1)
	{
		$sql="SELECT MaHD, MaKH, DATE_FORMAT(NgayLap,'%d/%m%/%Y') as NgayLap
			FROM hoadon
			WHERE (DATE_FORMAT(NgayLap,'%d') BETWEEN '$day' AND '$day1')
			AND (DATE_FORMAT(NgayLap,'%m') = '$mon')
			AND (DATE_FORMAT(NgayLap,'%Y') BETWEEN '$year' AND '$year1')";
		$this->query_db($sql);
		return $this->fetchAll();
	}
	function listcthd()
	{
		$sql="SELECT  MaCT,MaHD, MaMH, SoLuongBan, DonGiaBan
			FROM chitiethoadon";
		$this->query_db($sql);
		return $this->fetchAll();
	}
	function listcthoadon($id)
	{
		$sql="SELECT  MaHD, MaMH, SoLuongBan,DonGiaBan
			FROM chitiethoadon
			WHERE MaHD ='$id'";
		$this->query_db($sql);
		return $this->fetchAll();
	}
	function _listcthd($id)
	{
		$sql="SELECT  MaHD, MaMH, sum(SoLuongBan)as SoLuongBan, ROUND(AVG(DonGiaBan)) as DonGiaBan
			FROM chitiethoadon
			WHERE MaMH ='$id'";
		$this->query_db($sql);
		return $this->fetchOne();
	}
	function listmh(){
			$sql = "SELECT MaMH, MaLH, TenMH, DVT, SoLuong, Gia, HinhAnh, MoTa, AnHien
					FROM mathang";
			$this->query_db($sql);
			return $this->fetchAll();
		}
		function listctn($id){
			$sql = "SELECT MaCTN, MaNCC, MaMH, ROUND(AVG(DonGiaNhap)) as DonGiaNhap, SoLuongNhap, NgayNhap
					FROM chitietnhap
					WHERE MaMH ='$id'";
			$this->query_db($sql);
			return $this->fetchOne();
		}
		function listctnhap(){
			$sql = "SELECT MaCTN, MaNCC, MaMH, DonGiaNhap, SoLuongNhap, NgayNhap
					FROM chitietnhap
					";
			$this->query_db($sql);
			return $this->fetchAll();
		}
	
}